import {getToken, setToken, removeToken} from '@/utils/auth'

//引入axios
import axios from 'axios'


// 存储用户令牌和角色信息
const state = {
    token: getToken(),
    roles: [], //角色
    pwd: '',
    room: '',
    avatar: '',
    phone: '',
    qq: '',
    rid: '',
    userName: '',
    uid: ''
}

const mutations = {
    SET_TOKEN: (state, token) => {
        state.token = token;
    },
    SET_ROLES: (state, roles) => {
        state.roles = roles;
    },
    SET_AVATAR: (state, avatar) => {
        state.avatar = avatar;
    }
};

const actions = {
    // 用户登录
    login({commit}, userInfo) {
        let param = new URLSearchParams()
        param.append('name', userInfo.name)
        param.append('pwd', userInfo.pwd)
        return new Promise((resolve, reject) => {
            window.localStorage.setItem('userToken', "adminToken")
            resolve()
        })
    },
    // 重置令牌
    resetToken({commit}) {
        return new Promise(resolve => {
            window.localStorage.clear()
            resolve()
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
